package com.yzy.soft.system.controller;

//import com.sinosoft.liscw.system.service.IFormService;
//import com.sinosoft.liscw.common.persistence.model.Form;
//import com.sinosoft.liscw.common.persistence.dao.FormMapper;
import com.yzy.soft.system.domain.Form;
import com.yzy.soft.core.base.controller.BaseController;

import com.yzy.soft.system.freemarker.FormCodeGenerateUtils;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.util.HashMap;
import java.util.Map;

/**
* 描述：表单控制层
* @author Yinzhiyuan
* @date 2018-04-01 12:51:13
*/
@Api(value = "表单Controller",description = "表单控制接口")
@RestController
@RequestMapping("/form")
public class FormController extends BaseController{

//    @Autowired
//    private IFormService formService;
//
//    @Autowired
//    private FormMapper formMapper;

    
    
    /**
    * 描述：查询 表单列表
    */
//    @ApiOperation("查询表单")
//    @ApiImplicitParams({@ApiImplicitParam(name="page",value="当前页数",dataType="int", paramType = "query"),@ApiImplicitParam(name="limit",value="页数据条数",dataType="int", paramType = "query")})
//    @GetMapping(value = "",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public TableDataDto getAll(@RequestParam(name = "page", defaultValue = "1", required = true) int page, @RequestParam(name = "limit", defaultValue = "10", required = true) int pageSize)throws Exception {
//
//        Wrapper<Form> form=new EntityWrapper<Form>();
//        page=(page-1)*pageSize;
//        pageSize=page+pageSize;
//        List<Form> result=formMapper.selectPage(new RowBounds(page,pageSize),form);
//        TableDataDto tableDataDto=new TableDataDto();
//        tableDataDto.setCode("00");
//        tableDataDto.setMsg("000");
//        tableDataDto.setCount(formMapper.selectCount(form));
//        tableDataDto.setData(result);
//        return tableDataDto;
//    }
//
//    /**
//     * 描述：根据表单编号查询表单信息
//     */
//    @ApiOperation("根据表单编号查询表单信息")
//    @GetMapping(value = "/{id}")//,produces = MediaType.APPLICATION_JSON_UTF8_VALUE
//    public Form getById(@ApiParam(name="编码") @PathVariable("id") String id)throws Exception {
//        return formMapper.selectById(id);
//    }
//
//
//
//    /**
//    * 描述:创建表单
//    * @param form  表单DTO
//    */
//    @ApiOperation("创建表单")
//    @PostMapping("")
//    public Tip create(@ModelAttribute Form form) {
//        form.setCreate(new Date());
//        form.setUpdate(new Date());
//        Integer result=formMapper.insert(form);
//        return SUCCESS_TIP;
//    }
//
//    /**
//    * 描述：删除表单
//    * @param id 表单id
//    */
//    @ApiOperation("删除表单")
//    @DeleteMapping(value = "",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public Tip deleteById(@ModelAttribute Form form) throws Exception {
//        Integer result=formMapper.deleteById(form.getId());
//        return SUCCESS_TIP;
//    }
//
//    /**
//    * 描述：更新表单
//    * @param id 表单id
//    */
//    @ApiOperation("更新表单")
//    @PutMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public Tip updateForm(@ModelAttribute Form form) throws Exception {
//        form.setUpdate(new Date());
//        Integer result=formMapper.updateById(form);
//        return SUCCESS_TIP;
//    }
//
//    @ApiOperation("批量将表单设置成弃用状态")
//    @PostMapping("/batchNuUse")
//    public Tip batchNuUse(@RequestParam(name="ids[]",required = false) String[] form) {
//        if(rulesversion.length!=0){
//            Integer result=formMapper.batchNuUseIds(Lists.newArrayList(form) );
//        }
//        return SUCCESS_TIP;
//    }
//    @ApiOperation("批量将表单设置成可用状态")
//    @PostMapping("/batchUse")
//    public Tip batchUse(@RequestParam(name="ids[]",required = false) String[] rulesversion) {
//        if(form.length!=0){
//            Integer result=formMapper.batchUseIds(Lists.newArrayList(form) );
//        }
//        return SUCCESS_TIP;
//    }


    @ApiOperation("批量将表单设置成可用状态")
    @PostMapping("")
    public String  batchUse(@ModelAttribute Form form) throws Exception{
        Map<String,Object> dataMap=new HashMap<>();
        dataMap.put("type",form.getType());
        dataMap.put("label",form.getLabel());
        dataMap.put("value",form.getValue());
        dataMap.put("word_aux",form.getWord_aux());
//        dataMap.put();
        return FormCodeGenerateUtils.generateStringByTemplate("",dataMap);
    }

}